package com.yilin.tms.user.controller;

import com.yilin.commons.exception.BusinessException;
import com.yilin.tms.core.application.ReturnData;
import com.yilin.tms.core.commons.base.BaseController;
import com.yilin.tms.core.commons.annotation.NoLoginSecurity;
import com.yilin.tms.core.entity.user.RoleType;
import com.yilin.tms.core.entity.user.technical.GoodsConfigure;
import com.yilin.tms.core.entity.user.technical.TechnicalFeeRule;
import com.yilin.tms.core.entity.user.technical.LineConfigure;
import com.yilin.tms.user.service.IGoodsConfigureService;
import com.yilin.tms.user.service.ITechnicalFeeService;
import com.yilin.tms.user.service.ILineConfigureService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;


@RestController
@RequestMapping("/user/fee/")
public class FeeRuleController extends BaseController {

    @Resource
    ITechnicalFeeService technicalFeeService;
    @Resource
    ILineConfigureService lineConfigureService;
    @Resource
    IGoodsConfigureService goodsConfigureService;


    /**
     * 获取计价规则
     */
    @PostMapping(value = "getTechnicalFeeRule")
    @NoLoginSecurity
    public ReturnData<TechnicalFeeRule> getTechnicalFeeRule() {
        TechnicalFeeRule technicalFeeRule = technicalFeeService.getTechnicalFeeRule();
        return jsonView(SUCCESS_CODE, "获取成功", technicalFeeRule);
    }

    /**
     * 编辑计价规则
     */
    @PostMapping(value = "editTechnicalFeeRule")
    public ReturnData<Object> editTechnicalFeeRule(TechnicalFeeRule technicalFeeRule) {
        if (getLoginUser().getRoleType() != RoleType.manager) {
            throw new BusinessException("本次编辑仅限易林顶级管理员操作！");
        }
        technicalFeeRule.setUpdateUserId(getLoginUser().getId());
        technicalFeeRule.setUpdateTime(new Date());
        technicalFeeService.saveOrUpdateRule(technicalFeeRule);
        return jsonView(SUCCESS_CODE, "操作成功");
    }



}
